/**
 * Created by developer on 17-2-22.
 */
var $id;
var $status;
var $rightSlider = $(".aside-slider-content");
var $arr = ["size", "download_size"];
var $cover = $(".masking");
var $button = $("#brand_status .switch-animate");
var $test = true;
$(function () {
    var editPropertyIndex = null;
    //新增新商品品牌
    $(".add-product-brand").on("click", function () {
        $(".container-product-brand").children(".panel_header").html("新增商品品牌<span class='glyphicon glyphicon-remove cancel'></span>");
        modifyDisplayBlock($(".container-product-brand"));
        //关闭弹出框
        $(".container-product-brand").find(".cancel").on("click", function () {
            modifyDisplayNone($(".container-product-brand"));
        });
        //"保存并添加下一个"按钮显示
        $("#save_add_next").show();
    });
    //点击新增或编辑的弹出框，商品品牌状态切换按钮
    $button.on("click", function (e){
        console.log("Point");
        if ($test) {
            $(this).animate({left: "-50px"});
            $(this).removeClass("switch-on");
            $(this).addClass("switch-off");
            $test = false;
        }else{
            $(this).animate({left: "0px"});
            $(this).removeClass("switch-off");
            $(this).addClass("switch-on");
            $test = true;
        }
        e.stopPropagation();
    });
    //列表点击事件，出现侧栏
    $(".list-item").on("click", function () {
        // console.log($(this).attr("id"));
        var $currentId = $(this).attr("id");
        // expandOrCloseSidebar(getStatus($currentId), $currentId);
        console.log($rightSlider.css("right"));
        if ($rightSlider.css("right") == "-400px") {
            $rightSlider.animate({
                right: "0px"
            });
        } else {
            $rightSlider.animate({
                right: "-400px"
            });
        }
    });
    //关闭侧栏
    $rightSlider.find(".cancel").on("click", function () {
        $rightSlider.animate({right: "-400px"});
        $status = "close";
    });
    //编辑商品品牌
    $("#edit_product_brand").on("click", function () {
        $(".container-product-brand").children(".panel_header").html("修改商品基础属性模板<span class='glyphicon glyphicon-remove cancel'></span>");
        modifyDisplayBlock($(".container-product-brand"));
        //关闭弹出框
        $(".container-product-brand").find(".cancel").on("click", function () {
            modifyDisplayNone($(".container-product-brand"));
        });
        //"保存并添加下一个"按钮隐藏
        $("#save_add_next").hide();
    });
    //删除商品品牌
    $("#delete_product_brand").on("click", function () {
       modifyDisplayBlock($(".container-delete-product-brand"));
    });
    //关闭删除框
    $(".container-delete-product-brand").find(".cancel").on("click", function () {
        modifyDisplayNone($(".container-delete-product-brand"));
    });
});
//获取页面侧栏的打开或关闭的状态
function getStatus(currentId) {
    if ($id == currentId) {
        $status = "close";
        $id = "";
    } else {
        $status = "open";
        $id = currentId;
    }
    console.log($id);
    return $status;
}
//通过id对比打开或关闭页面侧栏
function expandOrCloseSidebar($status, currentId) {
    if ($status == "close") {
        $rightSlider.animate({right: "-400px"});
    } else if($status == "open") {
        for (var i = 0; i < $arr.length; i++) {
            if ($arr[i] == currentId) {
                $rightSlider.animate({right: "0px"});
            } else {
                console.log("没有对应的商品属性");
            }
        }
    }
}
//修改css样式display为block
function modifyDisplayBlock(obj) {
    obj.css("display", "block");
    $cover.css("display", "block");
}
//修改css样式display为none
function modifyDisplayNone(obj) {
    obj.css("display", "none");
    $cover.css("display", "none");
}